<template>
 <div class="home-new" ref="target">
    <!-- 插件传参  -->
<HomePanel :title="'新鲜好物'" :subTitle="'新鲜出炉 品质靠谱'">
    <!-- 插槽 需要用到虚拟标签 template 确定插槽位置-->
    <template v-slot:right >
        <XtxMore/>
    </template>
    <!-- 面板内容 -->
      <ul class="goods-list" v-if="newList.length>1">
        <li v-for="item in newList" :key="item.id">
          <RouterLink :to="`/product/${item.id}`">
            <img :src="item.picture" alt="">
            <p class="name ellipsis">{{item.name}}</p>
            <p class="price">&yen;{{item.price}}</p>
          </RouterLink>
        </li>
      </ul>
        <ul class="goods-list" v-else>
        <li v-for="item in 4" :key="item">
           <XtxSkeleton width='306px' height='406px'></XtxSkeleton>
        </li>
      </ul>
</HomePanel>
 </div>
</template>

<script setup>
import HomePanel from './home-panel.vue'
import { findNew } from '@/api/home'
import { ref } from 'vue'
import { useLazyData } from '@/hooks'
const newList = ref([])
const getList = async () => {
  const { result } = await findNew()
  newList.value = result
}
const target = useLazyData(getList)

</script>
<style scoped lang="less">
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    .hoverShadow();
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding: 12px 30px 0 30px;
      text-align: center;
    }
    .price {
      color: @priceColor;
    }
  }
}
</style>
